package com.lz.gmall.product.controller;

import com.lz.gmall.common.result.Result;
import com.lz.gmall.common.result.ResultCodeEnum;
import com.lz.gmall.service.FileUploadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/admin/product")
@Api(tags = "图片文件上传")
public class FileUploadController {

    @Autowired
    private FileUploadService fileUploadService;

    /**
     *
     * @param multipartFile 图片文件
     * @return 图片文件的地址
     */
    @PostMapping("/fileUpload")
    @ApiOperation("文件上传")
    public Result<String> fileUpload(@RequestParam("file") MultipartFile multipartFile){
        String url = fileUploadService.fileUpload(multipartFile);
        return Result.build(url, ResultCodeEnum.SUCCESS);
    }
}
